package com.neuedu.shop.service.impl;

import java.util.List;


import com.neuedu.shop.mapper.CategoryMapper;
import com.neuedu.shop.pojo.Category;
import com.neuedu.shop.pojo.CategoryRootBean;
import com.neuedu.shop.service.CategoryService;

/** 
* @author MrDCG 
* @version 创建时间：2019年9月28日 下午2:35:55 
*
*/
public class CategoryServiceImpl implements CategoryService {
	private CategoryMapper mapper;
	public CategoryServiceImpl() {}
	public CategoryServiceImpl(CategoryMapper mapper) {
		this.mapper = mapper;
		
	}
	@Override
	public void insertRoot(String categoryName, String categoryDescription) {
		mapper.insertRoot(new CategoryRootBean(categoryName,categoryDescription));
	}

	@Override
	public void insertChild(String name,String descr,int pid) {
		int grade = mapper.findByPid(pid);
		mapper.insertChild(new Category(name,descr,pid,grade+1));
		
		mapper.updateParent(pid);
	}

	@Override
	public List<Category> findAll() {
		return mapper.findAll();
	}

	@Override
	public List<Category> findToTree() {
		return mapper.findToTree();
	}

	@Override
	public void delete(int id, int pid) {
		// TODO Auto-generated method stub

	}
	

}
